<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/tipswindown.css" />
<script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
<%-- <script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script> --%>
<script type="text/javascript" src="${ctx}/js/tipswindown.js"></script>
<table class="display" id="example">
	<thead>
		<tr>
			<th>培训课程</th>
			<th>开始日期</th>
			<th>结束日期</th>
			<th>培训对象</th>
			<th>培训类型</th>
			<th>讲师</th>
			<th>教具清单</th>
			<th>标准教具</th>
			<th>额外教具</th>
		</tr>
	</thead>
	<tbody>
		<s:if test="#request.plans==null || #request.plans.size<=0">
			<tr class="gradeA">
				<td colspan="9">暂无数据</td>
			</tr>
		</s:if>
		<s:else>
			<s:iterator var="plan" status="sta" value="#request.plans">
				<s:if test="#sta.even">
					<tr class="gradeA">
				</s:if>
				<s:else>
					<tr class="gradeC">
				</s:else>
				<td>${plan.title}</td>
				<td><fmt:formatDate value="${plan.trainStartDate}"
						pattern="yyyy-MM-dd hh:mm" /></td>
				<td><fmt:formatDate value="${plan.trainEndDate}"
						pattern="yyyy-MM-dd hh:mm" /></td>
				<td><span name="td_dutytarget" title="${plan.id}"></span></td>
				<td>${plan.category}</td>
				<td><s:if test="#plan.lecturerType==0">${plan.trainLecturer.employeeinfoWork.baseId.name}</s:if>
					<s:else>${plan.outingLecturer}</s:else></td>
				<td><s:iterator var="realia" status="st"
						value="#plan.realiaResources">
						<a class="button" href="javascript:void(0)"><span
							style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>${realia.name}</a>
					</s:iterator></td>
				<td><a class="button" href="javascript:void(0)"
					onclick="onShowDiv(${plan.id})"><span
						style="background: url(${ctx}/images/img/cursor.png)"
						class="icon icon-ok">&nbsp;</span>选择</a></td>
				<td><a class="button" href="#train/realiaresource_apply.xhtml?planId=${plan.id}"><span
						style="background: url(${ctx}/images/img/script_go.png)"
						class="icon icon-ok">&nbsp;</span>申请</a></td>
				</tr>
			</s:iterator>
		</s:else>
	</tbody>
</table>
<p>
	<%@ include file="/WEB-INF/pages/common/main_orgtab_pager_train_resource.jsp"%>
</p>
<script type="text/javascript">
	function onShowDiv(planId) {
		//$("#config-popover").css("width", 900);
		tipsWindown(
				"选择教具",
				"url:post?${ctx}/train/realiaresource_select_list.xhtml?operation=select&organizationId=${organizationId}&planId=" + planId,
				"900", "350", "true", "", "true", "text");
	}

	//员工选择框返回事件
	function onSelectResource(chkObj,planId) {
		var resIds = "";
		chkObj.each(function(){
			resIds = resIds + this.value + ",";
		});
		resIds = resIds.length > 0 ? resIds.substring(0,resIds.length-1) : "";
		if(resIds.length > 0){
			$.ajax({
			    type: 'POST',
			    url:"${ctx}/ajax/post_planrealia_resource.xhtml",
			    data:{"resIds":resIds,"planId":planId},
			    dataType:"html",
			    success: function(response){
			    	if(response == "success"){
			    		alert("设置成功");
			    		loadListContent('/train/res_realia_list.xhtml','realia');
			    	}else{
			    		alert("设置失败，请联系管理员");
			    	}
			    	
			    }
			});
		}
	}
	
	$(document).ready(function() {
		$("span[name='td_dutytarget']").each(function(i) {
			loadDutyTarget(this, $(this).attr("title"));
		});
	});

	function loadDutyTarget(obj, planId) {
		$.ajax({
			type : "get",
			url : "/ajax/query_dutytarget.xhtml?planId=" + planId,
			//data: "name=John&location=Boston",
			dataType : "html",
			success : function(data) {
				if (data != null) {
					$(obj).html(data);
				}
			}
		});
	}
</script>
